<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\api\controller;

use app\service\common\Api;
use app\common\util\TokenAuth;
use app\common\model\User as UserModel;
use Webman\RateLimiter\Annotation\RateLimiter;

class Base extends Api
{
    protected $limit = 18;

    protected $user_id = 0;

    protected $user;

    #[RateLimiter(limit: 1)]
    public function __construct()
    {
        parent::__construct();

        $this->limit = $this->request->post('limit', 18);

        try {
            $jwt_user   = TokenAuth::parseToken('user');
            $this->user = UserModel::where([
                'id'     => $jwt_user['id'],
                'status' => 1
            ])->find();

            $this->user_id = $this->user->id;
        } catch (\Exception $e) {
            $this->user = null;
            $this->user_id = 0;
        }
    }
}